package cn.edu.nwsuaf.examcenter.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.nwsuaf.examcenter.pojo.College;
import cn.edu.nwsuaf.examcenter.pojo.Cource;
import cn.edu.nwsuaf.examcenter.pojo.CourceEmployee;
import cn.edu.nwsuaf.examcenter.pojo.CourceEmployeeId;
import cn.edu.nwsuaf.examcenter.pojo.Grade;
import cn.edu.nwsuaf.examcenter.pojo.Major;
import cn.edu.nwsuaf.examcenter.pojo.Sclass;
import cn.edu.nwsuaf.examcenter.pojo.Teacher;
import cn.edu.nwsuaf.examcenter.service.CollegeService;
import cn.edu.nwsuaf.examcenter.service.CourceEmployeeService;
import cn.edu.nwsuaf.examcenter.service.CourceService;
import cn.edu.nwsuaf.examcenter.service.GradeService;
import cn.edu.nwsuaf.examcenter.service.MajorService;
import cn.edu.nwsuaf.examcenter.service.SclassService;
import cn.edu.nwsuaf.examcenter.service.TeacherService;

@Controller
@RequestMapping(value="courceEmployee")
public class CourceEmployeeController {
	@Resource(name="collegeService")
	private CollegeService collegeService;
	@Resource(name="majorService")
	private MajorService majorService;
	@Resource(name="gradeService")
	private GradeService gradeService;
	@Resource(name="sclassService")
	private SclassService sclassService;
	
	@Resource(name="courceService")
	private CourceService courceService;
	
	@Resource(name="teacherService")
	private TeacherService teacherService;
	
	@Resource(name="courceEmployeeService")
	private CourceEmployeeService courceEmployeeService;
	
	/*-----------------分割线-----------------*/
	@ResponseBody
	@RequestMapping(value="/json/loadCourceEmployee")
	public CourceEmployee jsonLoadCourceEmployee(){
		CourceEmployeeId id = new CourceEmployeeId();
		id.setClassNo("SC0001");
		id.setCourceNo("C0002");
		id.setTeacherNo("2008000001");
		return courceEmployeeService.jsonLoadEmployee(id);
	}
	@ResponseBody
	@RequestMapping(value="/addCourceEmployee",method=RequestMethod.POST)
	public String addCourceEmployee(@RequestParam(value="courceNo")String courceNo, 
			@RequestParam(value="sclassNo")String sclassNo,
			@RequestParam(value="teacherNo")String teacherNo){
		return courceEmployeeService.addCourceEmployee(teacherNo, sclassNo, courceNo);
	}
	
	@ResponseBody
	@RequestMapping(value="/deleteCourceEmployee",method=RequestMethod.POST)
	public String deleteCourceEmployee(@ModelAttribute CourceEmployee courceEmployee){
		return courceEmployeeService.deleteCourceEmployee(courceEmployee);
	}
	/****
	 * Json获取学院信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/json/loadCollege")
	public List<College> jsonLoadCollege(){
		return collegeService.jsonLoadCollege();
	}
	
	/****
	 * Json获取学院信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/json/loadMajor/{collegeNo}")
	public List<Major> jsonLoadMajor(@PathVariable("collegeNo")String collegeNo){
		return majorService.jsonLoadMajor(collegeNo);
	}
	
	/****
	 * Json获取学院信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/json/loadGrade/{majorNo}")
	public List<Grade> jsonLoadGrade(@PathVariable("majorNo")String majorNo){
		return gradeService.jsonLoadGrade(majorNo);
	}
	
	/****
	 * Json获取学院信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/json/searchSclass")
	public List<Sclass> jsonSearchSclass(@RequestParam(value="gradeNo", required=false)String gradeNo, 
			@RequestParam(value="sclassName",required=false)String sclassName){
		return sclassService.jsonSearchSclass(gradeNo, sclassName);
	}
	
	/****
	 * 搜索课程
	 * @param courceName
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/json/searchCource")
	public List<Cource> jsonSearchCource(@RequestParam(value="courceName",required=false)String courceName){
		return courceService.jsonSearchCource(courceName);
	}
	
	@ResponseBody
	@RequestMapping(value="/json/searchTeacher")
	public List<Teacher> jsonSearchTeacher(@RequestParam(value="collegeNo",required=false)String collegeNo,
			@RequestParam(value="teacherName", required=false)String teacherName){
		return teacherService.jsonSearchTeacher(collegeNo, teacherName);
	}
	
	@RequestMapping(value="/loadCourceEmployee")
	public String loadCourceEmployee(@RequestParam(value="key",required=false)String key, 
			@RequestParam(value="p",required=false)String p,
			ModelMap modelMap){
		courceEmployeeService.loadCourceEmployee(modelMap);
		return "exam/cource-employee-list";
	}
}
